<?php
/*
	private $view - класс View
	private $args - переданные аргументы(GET)
 */
class IndexActionController 
{ 
	private $view;
	private $args;
	function __construct() {}
	public function setView(View $view) { 
		$this->view = $view; 
		return $this;
	} 
	public function setArgs($args = null) { 
		if(null != $args) { 
			$this->args = $args;
		}
		return $this->args; 
	} 
	public function run() {
		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
			$this->post();
		} else {
			$mapperAutors   = new MapperAutors();
			$mapperArticles = new MapperArtiles();
			$mapperTags     = new MapperTags();
			if (empty($this->args['get']['sorttag']) AND empty($this->args['get']['sorttag'])) {
				$articles = $mapperArticles->getAllArticles();
			}
			if (!empty($this->args['get']['sorttag'])) {
				$articles = $mapperArticles->getSortArticlesByTags($this->args['get']['sorttag']);
			}
			if (!empty($this->args['get']['sortautor'])) {
				$articles = $mapperArticles->getSortArticlesByAutor($this->args['get']['sortautor']);
			}
			$autors = $mapperAutors->getAllAutors();
			$tags   = $mapperTags->getAllTags();
			$this->view->setArticles($articles);
			$this->view->setAutors($autors);
			$this->view->setTags($tags);
			$this->view->setRenderTemplate("articles.php"); 
		}
	}
	public function post() {
		var_dump($this->args['post']);
	}
}
